<?php
$dt = new DataTable(constant('DB_TABLE_MEMBER'));
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if ( $act == 'ajax_set_subscribe') {
	$update_data = array('id'=>$_REQUEST['id']);
	$update_data['is_subscribe_epaper'] = isset($_REQUEST['is_subscribe_epaper']) && $_REQUEST['is_subscribe_epaper'] == 'Y'?'Y':'N';
	$dt->save($update_data);
	echo 'ok';
	exit();
}
elseif ( $act == 'ajax_set_delete') {
	$update_data = array('id'=>$_REQUEST['id'],'status'=>'delete');
	$dt->save($update_data);
	echo 'ok';
	exit();
}
elseif ( $act == 'ajax_delete') {
	$dt->remove($_REQUEST['id']);
	echo 'ok';
	exit();
}
$condition = "`status`='active'";
if (  isset($_REQUEST['key_word']) && strlen($_REQUEST['key_word']) > 0 ) {
	$key_word =  Util::sql_safe($_REQUEST['key_word']);
	$condition .= sprintf(" AND (`nick_name` = '%s' OR `email` = '%s' OR `display_name` = '%s')",$key_word,$key_word,$key_word);
}
$page = isset($_REQUEST['page'])?$_REQUEST['page']:1;
$page_size = isset($_REQUEST['page_size'])?$_REQUEST['page_size']:15;
$offset = $page_size * ( $page - 1);
$GLOBALS['PAGE_LIST_DATA'] = $dt->get_list($condition, 'id', $page_size, $offset);
$total_row =  $dt->get_count($condition);
$GLOBALS['PAGE_LIST_TOTAL_PAGE'] = ceil($total_row/$page_size);
$GLOBALS['PAGE_LIST_PAGE'] = $page;
$_REQUEST['page'] = $page;
?>
